package com.limengrui.Model;

import java.time.LocalDateTime;

//导入JPA提供的所有注解和类，例如@Entity
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity // Users 类是一个实体类，意味着它可以映射到数据库表
@Table(name = "users") // 该实体类对应的数据库表名是users
public class Users {
	@Id // 主键标注
	@GeneratedValue(strategy = GenerationType.IDENTITY) // 值是由数据库自动增长生成的。
	@Column(name = "id") // @Column用于设置本属性和数据表字段的映射关系，如果两者名称一致，可不写
	private Long id;

	@Column(nullable = false, updatable = false) // 和表的字段设置一致，不允许值为空
	private LocalDateTime createdAt;

	@Column(nullable = false)
	private LocalDateTime updatedAt;

	@Column(nullable = false, unique = true)
	private String username;

	@Column(nullable = false, unique = true)
	private String email;

	@Column(nullable = false)
	private String password;

	@Column(length = 1024)
	private String bio;

	@Column(length = 255)
	private String image;

	// Constructors
	public Users() {
		this.createdAt = LocalDateTime.now();
		this.updatedAt = LocalDateTime.now();
	}

	// 构造函数，参数均为前面@Column注解中不允许为空的属性
	public Users(String username, String email, String password) {
		this.username = username;
		this.email = email;
		this.password = password;

	}

	// JPA会通过反射机制调用 getter 和 setter 方法来访问和修改属性值，不写这些方法则导致获取数据失败

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public LocalDateTime getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(LocalDateTime createdAt) {
		this.createdAt = createdAt;
	}

	public LocalDateTime getUpdatedAt() {
		return updatedAt;
	}

	public void setUpdatedAt(LocalDateTime updatedAt) {
		this.updatedAt = updatedAt;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getBio() {
		return bio;
	}

	public void setBio(String bio) {
		this.bio = bio;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}
}
